﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.SceneControl.Scene;
using Engine.SceneControl;
using Engine.Material;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Engine;

namespace Etapa1.Screens
{
    public class DeepTechnic : IRenderTechnic
    {
        DeepShader dp;
        //ShadowShader ss;
        EngineStuff engine;
        List<DecoratedMaterial> _decs = new List<DecoratedMaterial>();
        //List<DecoratedMaterial> _decs2= new List<DecoratedMaterial>();

        #region IRenderTechnic Members

        public void Initialization(IRenderHelper render, Engine.SceneControl.IWorld world, Engine.EngineStuff engine)
        {
            this.engine = engine;
            dp = new DeepShader();
            dp.Initialize(engine);
            
            //ss = new ShadowShader();
            //ss.Initialize(engine);

            foreach (IObject item in world.Objects)
            {
                DecoratedMaterial dm = new DecoratedMaterial(item.Material, dp);
                item.Material = dm;
                _decs.Add(dm);
                dp.Update(item, world.Lights);
            
                //DecoratedMaterial dm2 = new DecoratedMaterial(item.Material, ss);
                //item.Material = dm2;
                //_decs2.Add(dm2);
                //ss.Update(item, world.Lights);

            }            
            render.SetQuadEffect(null);
            
        }

        public void ExecuteTechnic(IRenderHelper render, Engine.SceneControl.IWorld world)
        {
            foreach (DecoratedMaterial item in _decs)
            {
                item.OPMode = true;                                                
            }

            render.SetUpRenderTarget(Engine.SceneControl.Scene.RenderTarget.TEXTURE2D, RenderType.NORMALSCENE);
            render.RenderSceneWithMaterial("Deep");
            //render.RenderTextureToScreen("Deep");
            //render["Deep"].Save("teste.png", ImageFileFormat.Png);


            foreach (DecoratedMaterial item in _decs)
            {
                item.OPMode = false;
            }

            //foreach (DecoratedMaterial item in _decs2)
            //{
            //    item.OPMode = true;
            //    item.Shadder.EffectParameter["xTexture"].SetValue(render["Deep"]);
            //}

            //render.SetUpRenderTarget(Engine.SceneControl.Scene.RenderTarget.VIDEO, RenderType.NORMALSCENE);
            //render.RenderScene("Shadow");
            
            //foreach (DecoratedMaterial item in _decs2)
            //{
            //    item.OPMode = false;
            //}            
                
        }

        public string TechnicName
        {
            get { return "deep"; }
        }

        #endregion
    }
}
